#include"BlockQueue.hpp"
#include"Thread.hpp"
#include<vector>
#include<string>
#include<iostream>
using namespace yjt;
int a=10;
void Consumer(BlockQueue<int> &bq)
{
    while(true)
    {
        int data;
        bq.Pop(&data);
        cout<<"Consumer consum data is :"<<data<<endl;
    }
}
void Productor(BlockQueue<int> &bq)
{
    int cnt=10;
    while(true)
    {
        bq.Enqueue(cnt);
        cout<<"Productor product data is: "<<cnt++<<endl;
        sleep(1);
    }
}
void StartComm(vector<Thread<BlockQueue<int>>> *threads,int num,BlockQueue<int> &bq,func_t<BlockQueue<int>> func)
{
    for(int i=0;i<num;i++)
    {
        string name="thread-"+to_string(i+1);
        threads->emplace_back(func,bq,name);
        threads->back().Start();
    }
}
void StartConsumer(vector<Thread<BlockQueue<int>>> *threads,int num,BlockQueue<int> &bq)
{
    StartComm(threads,num,bq,Consumer);
}

void StartProductor(vector<Thread<BlockQueue<int>>> *threads,int num,BlockQueue<int> &bq)
{
    StartComm(threads,num,bq,Productor);
}
void WaitAllThread(vector<Thread<BlockQueue<int>>> &threads)
{
    for(auto &thread:threads)
    {
        thread.Join();
    }
}
int main()
{
    BlockQueue<int> *bq=new BlockQueue<int>(5); 
    vector<Thread<BlockQueue<int>>> threads;

    StartConsumer(&threads,1,*bq);
    StartProductor(&threads,1,*bq);
    WaitAllThread(threads);
    return 0;
}